package com.ei.itop.common.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.ailk.dazzle.util.type.DateUtils;

public class DateListUtil {
	
	public static List<String> getWeekList(Date startDate,Date endDate) throws Exception{
		List<String> weeks = new ArrayList<String>();
		Calendar c = Calendar.getInstance();
		c.setTime(endDate);
		int day = c.get(Calendar.DAY_OF_WEEK);
		//转换时间
		day = day==1?7:(day-1);
		endDate = DateUtils.dateOffset(endDate, Calendar.DAY_OF_YEAR, -day);
		while(endDate.getTime()>startDate.getTime()){
			StringBuilder sb = new StringBuilder();
			Date newEndDate = DateUtils.dateOffset(endDate, Calendar.DAY_OF_YEAR, -6);
			sb.append(DateUtils.date2String(newEndDate, DateUtils.FORMATTYPE_yyyy_MM_dd));
			sb.append("--");
			sb.append(DateUtils.date2String(endDate, DateUtils.FORMATTYPE_yyyy_MM_dd));
			weeks.add(sb.toString());
			endDate = DateUtils.dateOffset(newEndDate, Calendar.DAY_OF_YEAR, -1);
		}
		return weeks;
	}
	
	public static List<String> getMonthList(Date startDate,Date endDate) throws Exception{
		List<String> months = new ArrayList<String>();
		DateFormat df = new SimpleDateFormat("yyyy年MM月");
		while(endDate.getTime()>startDate.getTime()){
			months.add(df.format(endDate));
			endDate = DateUtils.dateOffset(endDate, Calendar.MONTH, -1);
		}
		return months;
	}
	
	public static void main(String[] args) throws Exception {
		getWeekList(DateUtils.string2Date("2015-09-16", DateUtils.FORMATTYPE_yyyy_MM_dd), DateUtils.string2Date("2016-09-16", DateUtils.FORMATTYPE_yyyy_MM_dd));
	}

}
